using CurrentUserDemo.Api.Extensions;
using CurrentUserDemo.Domain.OrderServices;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CurrentUserDemo.Api.Controllers;

[ApiController]
[Route("[controller]")]
[Authorize]
public class OrderController : ControllerBase
{
    private readonly OrderService _orderService;
    private readonly ICapPublisher _capPublisher;

    public OrderController(OrderService orderService, ICapPublisher capPublisher)
    {
        _orderService = orderService;
        _capPublisher = capPublisher;
    }

    [HttpPost]
    public string Create(string name)
    {
        var header = new Dictionary<string, string>()
        {
            ["my.header.first"] = "first",
            ["my.header.second"] = "second",
            ["my.header.orderName"] = name,
        };

        var orderTitle = _orderService.Create(name);
        _capPublisher.PublishEvent("test.show.time", DateTime.Now, header!);
        return orderTitle;
    }
}